package com.gpframework.module.manufacture.domain.req;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.gpframework.common.utils.DateUtils;
import com.gpframework.common.utils.StringUtils;
import com.gpframework.module.base.domain.req.BaseReq;
import com.gpframework.module.manufacture.domain.GpProductionScheduling;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.ToString;
import lombok.experimental.Accessors;
import org.apache.kafka.common.protocol.types.Field;

import java.util.Date;

/**
 * @ClassName GpProductionSchedulingReq
 * @Author gpframework
 * @Date 2023-12-12
 * @Version 1.0.0
 * @Description 列表查询信息体
 */
@Data
@ToString
@EqualsAndHashCode
@NoArgsConstructor
@Accessors(chain = true)
public class GpProductionSchedulingReq extends BaseReq {
    private static final long serialVersionUID = 1L;

         @ApiModelProperty("${column.columnComment}")
     private Long id;
     @ApiModelProperty("品牌id")
     private String brandId;
     @ApiModelProperty("品牌名称")
     private String brandName;
     @ApiModelProperty("订单号")
     private String sn;
     @ApiModelProperty("染厂id")
     private Long dyeingFactoryId;
     @ApiModelProperty("染厂名称")
     private String dyeingFactoryName;
     @ApiModelProperty("胚布基础表id")
     private Long supplierGreyClothId;
     @ApiModelProperty("供应商名称")
     private String supplierName;
     @ApiModelProperty("供应商胚布品名")
     private String supplierGreyClothName;
     @ApiModelProperty("产品基础表id")
     private Long produceProductId;
     @ApiModelProperty("产品名")
     private String productName;
     @ApiModelProperty("颜色")
     private String colour;
     @ApiModelProperty("颜色对照表id")
     private Long colourComparisonId;
     @ApiModelProperty("染厂色号（代码）")
     private String factoryColourCode;
     @ApiModelProperty("数量（件数）")
     private Integer quantity;
     @ApiModelProperty("回货日期")
     private Date returnTime;
     @ApiModelProperty("回货日期（开始）")
     private Date returnStartTime;
     @ApiModelProperty("回货日期（结束）")
     private Date returnEndTime;
     @ApiModelProperty("下单日期")
     private Date placeOrdersTime;
     @ApiModelProperty("下单日期（开始）")
     private Date placeOrdersStartTime;
     @ApiModelProperty("下单日期（结束）")
     private Date placeOrdersEndTime;
     @ApiModelProperty("进仓日期")
     private Date warehouseEntryTime;
     @ApiModelProperty("缸号")
     private String dyeVatNo;
     @ApiModelProperty("进仓重量")
     private Long warehouseEntryWeight;
     @ApiModelProperty("成品出仓重量")
     private Long warehouseExitWeight;
     @ApiModelProperty("胚布进仓批次")
     private String warehouseEntryNo;
     @ApiModelProperty("总重量")
     private Long totalWeight;
     @ApiModelProperty("剩余重量")
     private Long residualWeight;
     @ApiModelProperty("时长")
     private String duration;
     @ApiModelProperty("货期程度")
     private String degreeOfDeliveryTime;
     @ApiModelProperty("进度状态")
     private String progressStatus;
     @ApiModelProperty("是否生成到货单 0否 1是")
     private String deliveryNoteFlag;
     @ApiModelProperty("申请人id")
     private Long applicantId;
     @ApiModelProperty("申请人名称")
     private String applicantName;
     @ApiModelProperty("申请时间")
     private Date applicantTime;
     @ApiModelProperty("跟单人id")
     private Long followUpId;
     @ApiModelProperty("跟单人名称")
     private String followUpName;
     @ApiModelProperty("跟单时间")
     private Date followUpTime;
     @ApiModelProperty("操作人id")
     private Long operatorId;
     @ApiModelProperty("操作人名称")
     private String operatorName;
     @ApiModelProperty("操作时间")
     private Date operatorTime;
     @ApiModelProperty("排序")
     private Integer sort;
     @ApiModelProperty("备注")
     private String remarks;
     @ApiModelProperty("创建者")
     private String createBy;
     @ApiModelProperty("创建时间")
     private Date createTime;
     @ApiModelProperty("更新者")
     private String updateBy;
     @ApiModelProperty("更新时间")
     private Date updateTime;
     @ApiModelProperty("删除标记;0未删除。1已删除。")
     private Integer delStatus;
    @ApiModelProperty("查询条件（订单号/客户名）")
    private String searchName;
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date searchDate;

    @ApiModelProperty("染厂胚布品名")
    private String dyeingGreyClothName;
    /** 操作人编号 */
    private String operatorNum;

    /**审批人名称 */
    private String examinName;

    /** 实际胚布用量 */
    @ApiModelProperty("实际胚布用量")
    private Integer actualGreyUsed;

    /** 胚布库存数量 */
    @ApiModelProperty("胚布库存数量")
    private Integer stockGreyNum;

    /** 胚布剩余数量 */
    @ApiModelProperty("胚布剩余数量")
    private Integer leaveGreyNum;

    /**
    * @Description 生成查询wrapper
    * @Author greatplan@qq.com
    * @Date 2020-11-04 16:04
    * @Param [lqw]
    * @Param [isVO] 是否vo查询体，true的话走的是mapper.xml里面的查询语句，不过查询语法还是mybatis-plus，主要用于某些关联查询出一些非数据表字段
    * @Return void
    */
    public void generatorQuery(QueryWrapper<GpProductionScheduling> lqw,boolean isVo) {
        String alias = "";
        if (isVo) {
            alias = "gp.";
            lqw.eq(alias+"del_status",0);
            lqw.orderByDesc(alias+"create_time");
        }
        if (this.getId() != null){
        lqw.eq(alias+"id" ,this.getId());
        }
        if (StringUtils.isNotBlank(this.getBrandId())){
        lqw.eq(alias+"brand_id" ,this.getBrandId());
        }
        if (StringUtils.isNotBlank(this.getBrandName())){
            lqw.like(alias+"brand_name",this.getBrandName());
        }
        if (StringUtils.isNotBlank(this.getSn())){
        lqw.like(alias+"sn" ,this.getSn());
        }
        if (this.getDyeingFactoryId() != null){
        lqw.eq(alias+"dyeing_factory_id" ,this.getDyeingFactoryId());
        }
        if (StringUtils.isNotBlank(this.getDyeingFactoryName())){
            lqw.like(alias+"dyeing_factory_name",this.getDyeingFactoryName());
        }
        if (this.getSupplierGreyClothId() != null){
        lqw.eq(alias+"supplier_grey_cloth_id" ,this.getSupplierGreyClothId());
        }
        if (StringUtils.isNotBlank(this.getSupplierName())){
            lqw.like(alias+"supplier_name",this.getSupplierName());
        }
        if (StringUtils.isNotBlank(this.getSupplierGreyClothName())){
            lqw.like(alias+"supplier_grey_cloth_name",this.getSupplierGreyClothName());
        }
        if (this.getProduceProductId() != null){
        lqw.eq(alias+"produce_product_id" ,this.getProduceProductId());
        }
        if (StringUtils.isNotBlank(this.getProductName())){
            lqw.like(alias+"product_name",this.getProductName());
        }
        if (StringUtils.isNotBlank(this.getColour())){
        lqw.eq(alias+"colour" ,this.getColour());
        }
        if (this.getColourComparisonId() != null){
        lqw.eq(alias+"colour_comparison_id" ,this.getColourComparisonId());
        }
        if (StringUtils.isNotBlank(this.getFactoryColourCode())){
        lqw.like(alias+"factory_colour_code" ,this.getFactoryColourCode());
        }
        if (this.getQuantity() != null){
        lqw.eq(alias+"quantity" ,this.getQuantity());
        }
        if (this.getReturnTime() != null){
        lqw.eq(alias+"return_time" ,this.getReturnTime());
        }
        if (this.getReturnStartTime() != null && this.getReturnEndTime() != null){
        lqw.between(alias+"return_time" ,this.getReturnStartTime(), this.getReturnEndTime());
        }
        if (this.getPlaceOrdersTime() != null){
        lqw.eq(alias+"place_orders_time" ,this.getPlaceOrdersTime());
        }
        if (this.getPlaceOrdersStartTime() != null && this.getPlaceOrdersEndTime() != null){
            lqw.between(alias+"place_orders_time" ,this.getPlaceOrdersStartTime(), this.getPlaceOrdersEndTime());
        }
        if (this.getWarehouseEntryTime() != null){
        lqw.eq(alias+"warehouse_entry_time" ,this.getWarehouseEntryTime());
        }
        if (StringUtils.isNotBlank(this.getDyeVatNo())){
        lqw.eq(alias+"dye_vat_no" ,this.getDyeVatNo());
        }
        if (this.getWarehouseEntryWeight() != null){
        lqw.eq(alias+"warehouse_entry_weight" ,this.getWarehouseEntryWeight());
        }
        if (this.getWarehouseExitWeight() != null){
        lqw.eq(alias+"warehouse_exit_weight" ,this.getWarehouseExitWeight());
        }
        if (StringUtils.isNotBlank(this.getWarehouseEntryNo())){
        lqw.eq(alias+"warehouse_entry_no" ,this.getWarehouseEntryNo());
        }
        if (this.getTotalWeight() != null){
        lqw.eq(alias+"total_weight" ,this.getTotalWeight());
        }
        if (this.getResidualWeight() != null){
        lqw.eq(alias+"residual_weight" ,this.getResidualWeight());
        }
        if (this.getDuration() != null){
        lqw.eq(alias+"duration" ,this.getDuration());
        }
        if (StringUtils.isNotBlank(this.getDegreeOfDeliveryTime())){
        lqw.eq(alias+"degree_of_delivery_time" ,this.getDegreeOfDeliveryTime());
        }
        if (StringUtils.isNotBlank(this.getProgressStatus())){
        lqw.eq(alias+"progress_status" ,this.getProgressStatus());
        }
        if (StringUtils.isNotBlank(this.getDeliveryNoteFlag())){
        lqw.eq(alias+"delivery_note_flag" ,this.getDeliveryNoteFlag());
        }
        if (this.getApplicantId() != null){
        lqw.eq(alias+"applicant_id" ,this.getApplicantId());
        }
        if (StringUtils.isNotBlank(this.getApplicantName())){
            lqw.like(alias+"applicant_name",this.getApplicantName());
        }
        if (this.getApplicantTime() != null){
        lqw.eq(alias+"applicant_time" ,this.getApplicantTime());
        }
        if (this.getFollowUpId() != null){
        lqw.eq(alias+"follow_up_id" ,this.getFollowUpId());
        }
        if (StringUtils.isNotBlank(this.getFollowUpName())){
            lqw.like(alias+"follow_up_name",this.getFollowUpName());
        }
        if (this.getFollowUpTime() != null){
        lqw.eq(alias+"follow_up_time" ,this.getFollowUpTime());
        }
        if (this.getOperatorId() != null){
        lqw.eq(alias+"operator_id" ,this.getOperatorId());
        }
        if (StringUtils.isNotBlank(this.getOperatorName())){
            lqw.like(alias+"operator_name",this.getOperatorName());
        }
        if (this.getOperatorTime() != null){
        lqw.eq(alias+"operator_time" ,this.getOperatorTime());
        }
        if (this.getSort() != null){
        lqw.eq(alias+"sort" ,this.getSort());
        }
        if (StringUtils.isNotBlank(this.getRemarks())){
        lqw.eq(alias+"remarks" ,this.getRemarks());
        }
        if (StringUtils.isNotBlank(this.getCreateBy())){
        lqw.eq(alias+"create_by" ,this.getCreateBy());
        }
        if (this.getCreateTime() != null){
        lqw.eq(alias+"create_time" ,this.getCreateTime());
        }
        if (StringUtils.isNotBlank(this.getUpdateBy())){
        lqw.eq(alias+"update_by" ,this.getUpdateBy());
        }
        if (this.getUpdateTime() != null){
        lqw.eq(alias+"update_time" ,this.getUpdateTime());
        }
        if (this.getDelStatus() != null){
        lqw.eq(alias+"del_status" ,this.getDelStatus());
        }
        if (StringUtils.isNotBlank(this.getSearchName())) {
            lqw.and(wrapper -> wrapper.like("gp.sn", this.getSearchName()).or().like("gp.product_name", this.getSearchName()).or().like("gp.colour", this.getSearchName()));
        }
        if (this.getSearchDate() != null) {
            lqw.apply("DATE_FORMAT(gp.create_time, '%Y-%m-%d') = '" + DateUtils.dateTime(this.getSearchDate()) + "'");
        }
    }
}
